/*
 * Conexion.java
 *
 * Creada el 22 de noviembre de 2007, 11:12 AM
 *
 */

package FachadaDatos;

import CapaLogica.*;
import com.sun.crypto.provider.RSACipher;
import java.util.*;
import java.io.*;
import java.net.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
import FachadaInterfaz.*;

/**
 *
 * @author Solware
 */
public class Conexion {
    
    public static Connection conexion;
    
    public static void conectar() {
        conexion = null;
        try {
            // Cargar el driver JDBC
            String driverName = "org.postgresql.Driver"; // postgresql JDBC driver
            Class.forName(driverName);
            // Crear la conexion a la base de datos
            String serverName = "localhost:5432";
            String mydatabase = "sast";
            String driver = driverName;
            String url = "jdbc:postgresql://" + serverName +  "/" + mydatabase; //a JDBC url
            String username = "postgres";
            String password = "12345";
            Class.forName(driver);
            conexion = DriverManager.getConnection(url, username, password);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    
    public static void desconectar() {
        if (conexion != null) {
            try {
                conexion.close();
            } catch (SQLException ex) {
                ex.printStackTrace();
            }
        }
    }
}
